<%--
  Created by IntelliJ IDEA.
  User: wj
  Date: 2018-11-24
  Time: 14:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <link href="${pageContext.request.contextPath}/static/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

    <link href="${pageContext.request.contextPath}/static/hplus/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">

    <script>
        //得到查询的参数
        function queryParams (params) {
        };

        $(function () {
            $("#usertb").bootstrapTable({
                url:'${pageContext.request.contextPath}/shangpin/querySearch',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:15,
                pageList:[2,4,8,16],
                height:550,
                clickToSelect:true,
                singleSelect:true,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
                // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        uname:$("#uname").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        checkbox:true,
                    },
                    {
                        field:'sid',
                        title:'商品编号'
                    },
                    {
                        field:'sname',
                        title:'商品姓名'
                    },
                    {
                        field:'lid',
                        title:'类别',
                        formatter (value, row1, index, field) {
                            if (row1.lid == 1) {
                                return "白酒类";
                            } else if (row1.lid == 2) {
                                return "饮料类";
                            } else if (row1.lid == 3) {
                                return "水果类";
                            } else if (row1.lid == 4) {
                                return "食品类";
                            }
                        }
                    },
                    {
                        field:'sguige',
                        title:'商品规格'
                    },
                    {
                        field:'sjiage',
                        title:'商品价格'
                    },
                    {
                        field:'did',
                        title:'单位',
                        formatter (value, row, index, field){
                            if (row.did == 1) {
                                return "斤";
                            }else if(row.did == 2){
                                return "瓶";
                            }else if(row.did == 3){
                                return "盒";
                            }else if(row.did == 4){
                                return "袋";
                            }
                        }
                    },
                    {
                        field:'skucun',
                        title:'商品库存'
                    },

                ]
            }) ;
        }) ;


        function searcha() {
            var opts = $("#usertb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var sname = $("#sname").val() ;
            $.post("${pageContext.request.contextPath}/shangpin/querySearch",{'sname':sname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#usertb").bootstrapTable('load',data) ;
            })
        }


        var sid = sid;

        function tofenpei(){
            var myrows =  $("#usertb").bootstrapTable("getSelections") ;
            if(myrows.length==0){
                alert("请选中要添加的商品!") ;
            }
            else{
                $("[name=shuliang]").val(1);
                //得到选中行的主键
                id = myrows[0].sid ;
                $("#div1").modal("show") ;

                $.post('${pageContext.request.contextPath}/shangpin/getsid',{'sid':id},function(data){
                    $("#Div2").modal('show');
                    //绑定事件
                    $("#Div2").on('shown.bs.modal',function(e){
                        //给表单赋值

                        $("[name=sid]").val(data.sid);
                        $("[name=sname]").val(data.sname);
                        $("[name=skucun]").val(data.skucun);
                        $("[name=sguige]").val(data.sguige);
                        $("[name=sjiage]").val(data.sjiage);
                        $("[name=lid]").val(data.lid);

                        $("[name=did]").val(data.did);
                    })
                })
            }
        }

        function newNnb() {
            var yua=$("[name=skucun]").val();
            var num = $("#juesebody3 input[name=shuliang]").val();
            var tos = $("#juesebody4 input[name=sjiage]").val();
            if(parseInt(yua)>=num){
            $("#juesebody5 input[name=sjiage]").val(parseInt(num) * parseInt(tos).toFixed(1));
                $("#tianjia").attr('disabled',false);
            }else{
                $("#tianjia").attr('disabled',true);
            }
        }



        function doadd(){
            var xiaoidG=$("#sid").val();
            var xiaonameG=$("#shname").val();
            var xiaoleiG=$("#lid").val();
            var xiaoshuG=$("#shuliang").val();
            var xiaojiaG=$("#sjiage").val();
            var xiaodanG=$("#did").val();
            var xiaozongjiaG=$("#zongjia").val();
            $.post('${pageContext.request.contextPath}/xiaoshou/addls',{"xiaoid":xiaoidG,'xiaoname':xiaonameG,'xiaolei':xiaoleiG,'xiaoshu':xiaoshuG,'xiaojia':xiaojiaG,'xiaodan':xiaodanG,'xiaozongjia':xiaozongjiaG},function(data){
                if(data>0){
                    // var mydata = eval("("+data+")") ;
                    //重新绑定表格数据
                    $("#Div2").modal('hide');
                }
            });
        }

    </script>


</head>
<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4" >
        <h4>商品销售</h4>
        <ol class="breadcrumb">

        </ol>
    </div>

</div>

<div class="wrapper wrapper-content" style="background: #EDF2F8">
    <div class="row">
        <div class="col-md-1"style="margin-left:700px; margin-top: -20px">
            <div class="title-action">
                <input id="sname" type="text" class="form-control">
            </div>
        </div>


        <div class="col-md-1"style="margin-left:800px; margin-top: -35px">
            <button onclick='searcha()' class="btn btn-primary">查询</button>
        </div>

        <div class="col-md-1"style="margin-left:880px; margin-top: -65px">
            <div class="title-action">
                <button onclick='tofenpei()' class="btn btn-primary">添加商品</button>
            </div>
        </div>
    </div>
</div>


<div class="panel panel-default">
    <div class="panel-body" <%--style="width:850px;height:850px"--%>>
        <table id="usertb"></table>
    </div>
</div>


<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="Div2">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" >采购进货</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品名称:</h2></label>
                    <div class="col-sm-4" id="juesebody" style="margin-top: 15px">
                        <input style="color: #010101" id="shname" name="sname" type="text" readOnly="true" class="form-control">
                        <input style="color: #010101" name="sid" id="sid"  type="hidden"  readOnly="true" class="form-control">
                        <input style="color: #010101" name="lid" id="lid"  type="hidden"  readOnly="true" class="form-control">
                        <input  name="did" id="did" type="hidden"  readOnly="true" class="form-control">

                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品库存:</h2></label>
                    <div class="col-md-4" id="juesebody1" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px" name="skucun" type="text" readOnly="true" class="form-control">
                    </div>
                    <label class="col-sm-2 control-label"><h2>商品规格:</h2></label>
                    <div class="col-md-4" id="juesebody2" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px" id="sguige" name="sguige" type="text" readOnly="true" class="form-control">
                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品进价:</h2></label>
                    <div class="col-md-4" id="juesebody4" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px" id="sjiage" name="sjiage" type="text" onkeyup="newNnb()"  class="form-control">
                    </div>
                    <label class="col-sm-2 control-label"><h2>商品数量:</h2></label>
                    <div class="col-md-4" id="juesebody3" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px" id="shuliang" name="shuliang" onkeyup="newNnb()" value="1" type="text" class="form-control">
                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品总价:</h2></label>
                    <div class="col-md-4" id="juesebody5" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 150px" id="zongjia" name="sjiage" readOnly="true" type="text"  class="form-control">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button onclick="doadd()" id="tianjia" type="button" class="btn btn-primary">添加</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
